package br.art.late.openenvironment.boids;

import br.art.late.openenvironment.main.OpenEnvironment;
import processing.core.PApplet;
import processing.core.PVector;
/**
 * Zone class for Processing, Nicolas Liautaud 2009 <br/>
 * Used by BoidsFlock class
 */

public class Zone {
	int x, y, w, h;
	OpenEnvironment parent;

	Zone(int _x, int _y, int _w, int _h, OpenEnvironment parent) {
		x = _x;
		y = _y;
		w = _w;
		h = _h;
		this.parent = parent;
	}

	// define if coord is in zone
	public boolean isIn(PVector v) {
		return isIn(PApplet.parseInt(v.x), PApplet.parseInt(v.y));
	}

	public boolean isIn(int px, int py) {
		if (px > x && px < x + w && py > y && py < y + h)
			return true;
		else
			return false;
	}

	// return a random pos vector in zone
	public PVector randomPos() {
		return new PVector(parent.random(x, x + w), parent.random(y, y + h));
	}

	// display a border around zone
	public void border(int a) {
		parent.noFill();
		//parent.stroke(a);
		parent.rectMode(parent.CORNER);
		parent.rect(x, y, parent.width, parent.height);
	}
}
